<?php
namespace app\app\controller\v1;
use app\app\util\OnlineUtils;
use app\app\model\HouseModel;

class HouseController extends BaseController{


    /**
     * 闯关模式获取题目
     */
    public function blockade(){
        $user_id = OnlineUtils::getUserIdBySid();
        $house = new HouseModel();
        //id字符串
        try{
            $block = $house->getHouse(input('post.id'));
        }catch(Exception $e){
            return jsonReturn(402,'选题失败');
        }
        //处理数据
        $result = json_decode($block['result'],true);
        $arr    = array(array('id'=>'A','name'=>$result['A']),array('id'=>'B','name'=>$result['B']),array('id'=>'C','name'=>$result['C']),array('id'=>'D','name'=>$result['D']));
        foreach($arr as $k => $v){
            if($v['id'] == $block['answer']){
                $arr[$k]['is_true'] = 1;
            }else{
                $arr[$k]['is_true'] = 0;
            }
        }
        $block['answer'] = $arr;
        unset($block['result']);
        unset($block['status']);
        return jsonReturn(200,'success',$block);
    }



}